package com.lin.rmi;

import java.io.IOException;
import java.rmi.AlreadyBoundException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 * @ClassName RMIServer
 * @Description
 * @Author lin
 * @Date 2022/7/6 上午12:32
 * @Version V1.0
 */
public class RMIServer {
    public static void main(String[] args) {
        IRemote remoteHello = new RemoteImpl();
        try {
            IRemote stub = (IRemote) UnicastRemoteObject.exportObject(remoteHello, 4000); //导出服务，使用4000端口
            Registry registry = LocateRegistry.getRegistry("127.0.0.1", 8000); //获取Registry
            registry.bind("name", stub); //使用名字hello，将服务注册到Registry
        } catch (IOException | AlreadyBoundException e) {
            e.printStackTrace();
        }
    }
}
